package top.zlcode.common.core.domain;

import lombok.Getter;
import lombok.Setter;
import top.zlcode.common.core.enums.ResultCode;

import java.util.ArrayList;
import java.util.List;

/**
 * 表格分页数据对象
 */
@Setter
@Getter
public class TableDataInfo {
    private long total;

    private List<?> rows;

    private int code;

    private String msg;

    public TableDataInfo(){}

    public static TableDataInfo empty() {
        TableDataInfo resData = new TableDataInfo();
        resData.setCode(ResultCode.SUCCESS.getCode());
        resData.setRows(new ArrayList<>());
        resData.setMsg(ResultCode.SUCCESS.getMsg());
        resData.setTotal(0);
        return resData;
    }

    public static TableDataInfo success(List<?> list, long total) {
        TableDataInfo resData = new TableDataInfo();
        resData.setCode(ResultCode.SUCCESS.getCode());
        resData.setRows(list);
        resData.setMsg(ResultCode.SUCCESS.getMsg());
        resData.setTotal(total);
        return resData;
    }
}
